import {VuexModule, Module, Action} from 'vuex-class-modules'
import UserStorageUtil from "@/utils/UserStorageUtil";
import UserVO from "@/model/user/UserVO";
import UserAPI from "@/api/UserAPI";

//用来存储当前用户的一些信息
@Module({generateMutationSetters: true})
export default class UserModule extends VuexModule {
  user: UserVO = null
  phoneNum = '123'
  // user: UniUserVO = UserStorageUtil.get() || null

  setUser(user: UserVO) {
    this.user = user
    UserStorageUtil.set(user)
  }

  hasUser(): boolean {
    return !!this.user
  }

  /**
   * 调用后台仅获取user信息
   */
  @Action
  getMineUserAction () {
    return UserAPI.getMineUserInfoAPI().then((res: any) => {
      this.setUser(res.data)
    })
  }
}
